/*
 *
 * Created on: 19.09.2012
 *
 * log.h
 * This file is part of KOBUS
 * 
 * Copyright (C) 2012 - Ivan Penkin, MIPT
 * grek.penkin@gmail.com
 *
 * KOBUS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * KOBUS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with KOBUS; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, 
 * Boston, MA  02110-1301  USA
 *  
 */

#ifndef LOG_H_
#define LOG_H_

#include <KobusCommon_global.h>

#include <qobject.h>


namespace kobus {

class LogPrivate;

class KOBUS_COMMON_EXPORT Log: public QObject
{
    Q_OBJECT

  public:
    enum Priority {
      LOG_EMERG = 0,
      LOG_ALERT = 1,
      LOG_CRIT = 2,
      LOG_ERR = 3,
      LOG_WARNING = 4,
      LOG_NOTICE = 5,
      LOG_INFO = 6,
      LOG_DEBUG = 7
    };

    enum Facility {
      LOG_KERN      = (0<<3),
      LOG_USER      = (1<<3),
      LOG_MAIL      = (2<<3),
      LOG_DAEMON    = (3<<3),
      LOG_AUTH      = (4<<3),
      LOG_SYSLOG    = (5<<3),
      LOG_LPR       = (6<<3),
      LOG_NEWS      = (7<<3),
      LOG_UUCP      = (8<<3),
      LOG_CRON      = (9<<3),
      LOG_AUTHPRIV  = (10<<3),
      LOG_FTP       = (11<<3),

      LOG_LOCAL0   = (16<<3),
      LOG_LOCAL1   = (17<<3),
      LOG_LOCAL2   = (18<<3),
      LOG_LOCAL3   = (19<<3),
      LOG_LOCAL4   = (20<<3),
      LOG_LOCAL5   = (21<<3),
      LOG_LOCAL6   = (22<<3),
      LOG_LOCAL7   = (23<<3)
    };

    enum Option {
      LOG_PID    = 0x01,
      LOG_CONS   = 0x02,
      LOG_ODELAY = 0x04,
      LOG_NDELAY = 0x08,
      LOG_NOWAIT = 0x10,
      LOG_PERROR = 0x20
    };

    enum DebugLevel {
      FACILE = 1,
      NORMAL,
      DEEP,
      EXTRA
    };

    Log(QObject * parent = 0);
    Log(const QString & ident, Option opt, Facility facility, QObject * parent = 0);
    virtual
    ~Log();

    virtual
    void write(Priority priority, const char* format, ...) const;
    virtual
    void writeDebug(DebugLevel level, const char * format, ...) const;

    virtual
    void error(const char* format, ...) const;
    virtual
    void warning(const char* format, ...) const;
    virtual
    void notice(const char* format, ...) const;
    virtual
    void info(const char* format, ...) const;

  public slots:
    virtual
    void write(Priority priority, const QString & msg) const;
    virtual
    void writeDebug(DebugLevel level, const QString & msg) const;

    virtual
    void error(const QString & msg) const;
    virtual
    void warning(const QString & msg) const;
    virtual
    void notice(const QString & msg) const;
    virtual
    void info(const QString & msg) const;

  protected:
    Log(LogPrivate * dd, QObject * parent);

    static LogPrivate * d_ptr;
    static int          debugLevel;

  private:
    Q_DECLARE_PRIVATE(Log);
    Q_DISABLE_COPY(Log);
};

} /* namespace kobus */

Q_DECLARE_TYPEINFO(kobus::Log, Q_MOVABLE_TYPE);

#endif /* LOG_H_ */
